package com.flyme.module.base.provider.service.impl;

import com.flyme.common.core.model.ResultBody;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysExamtype;
import com.flyme.module.base.provider.mapper.SysExamtypeMapper;
import com.flyme.module.base.provider.service.SysExaminationService;
import com.flyme.module.base.provider.service.SysExamtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysExamtypeServiceImpl extends BaseServiceImpl<SysExamtypeMapper, SysExamtype> implements SysExamtypeService {

    @Autowired
    private SysExaminationService examinationService;

    @Override
    public Boolean addExamType(SysExamtype examType) {
        return save(examType);
    }


    @Override
    public Boolean updateExamType(SysExamtype examType) {
        return saveOrUpdate(examType);
    }

    @Override
    public ResultBody delById(Long examTypeId) {
        Integer num = examinationService.countByType(examTypeId);
        if(num > 0){
            return ResultBody.failed("请先清空该分类下的考试");
        }
        removeById(examTypeId);
        return ResultBody.success("刪除成功");
    }

}
